﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.pad
{
    public partial class StockProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<StockEntity> entryList = new List<StockEntity>();

            StockEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new StockEntity();
                    entry.PartNum = item[StockEntity.PART_NUM].ToString();
                    entry.PartDescription = item[StockEntity.PART_DESCRIPTION].ToString();
                    entry.AllNW = Convert.ToDecimal(item[StockEntity.ALL_NW].ToString());
                    entry.BinNum = item[StockEntity.BIN_NUM].ToString();
                    entry.ClassDescription = item[StockEntity.CLASS_DESCRIPTION].ToString();
                    entry.CommodityCode = item[StockEntity.COMMODITY_CODE].ToString();
                    entry.Contract = item[StockEntity.CONTRACT].ToString();
                    entry.ContractNW = Convert.ToDecimal(item[StockEntity.CONTRACT_NW].ToString());
                    entry.GroupDescription = item[StockEntity.GROUP_DESCRIPTION].ToString();
                    entry.IUM = item[StockEntity.IUM_S].ToString();
                    entry.LotNum = item[StockEntity.LOT_NUM].ToString();
                    entry.NetWeight = Convert.ToDecimal(item[StockEntity.NET_WEIGHT].ToString());
                    entry.OnhandQty = Convert.ToDecimal(item[StockEntity.ONHAND_QTY].ToString());
                    entry.OldPartNum = item[StockEntity.OLD_PART_NUM].ToString();
                    entry.RunOut = Convert.ToBoolean(item[StockEntity.RUN_OUT].ToString());
                    entry.TotalNW = Convert.ToDecimal(item[StockEntity.TOTAL_NW].ToString());
                    entry.TrackLots = Convert.ToBoolean(item[StockEntity.TRACK_LOTS].ToString());
                    entry.TypeCode = item[StockEntity.TYPE_CODE].ToString();

                    entry.WarehouseCode = item[StockEntity.WAREHOUSE_CODE].ToString();
                    entry.WarehseDescription = item[StockEntity.WAREHSE_DESCRIPTION].ToString();
                    entry.WhseBinDescription = item[StockEntity.WHSEBIN_DESCRIPTION].ToString();
                                  
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
